<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class GoodsAttributes extends Model
{
    use SoftDeletes;
    protected $table = 'goods_attributes';
    protected $fillable=[ 'name', 'sort' ];

    protected $appends = ['list_value'];

    public function hasManyValue()
    {
        return $this->hasMany(GoodsAttributesValue::class,'attribute_id','id');
    }

    public function manyType()
    {
        return $this->belongsToMany(GoodsType::class,'goods_type_attributes','attribute_id','type_id');
    }

    public function getListValueAttribute()
    {
        return GoodsAttributesValue::where('attribute_id',$this->id)->get();
    }
}
